package com.lxk.dao;

import com.lxk.pojo.*;
import com.lxk.vo.*;
import com.lxk.vo.OrdersInfoModel;
import com.lxk.vo.param.OrdersParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author JohnSoybean
 * @create 2020/3/26 12:35
 * @description
 */
public interface AsMyMapper {

    /**
     * 获取微信用户id列表
     * @return
     */
    @Select("SELECT wx_user_id FROM wx_user")
    List<Integer> getWxUserIdList();

    /**
     * 获取已下架普通商品数量
     * @return
     */
    @Select("SELECT COUNT(g.goods_id) FROM goods g LEFT OUTER JOIN goods_stat gs ON g.goods_id = gs.goods_id " +
            "WHERE gs.is_upper = 0" )
    Integer getDownGoodsNum();

    /**
     * 查找已下架普通商品分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<GoodsNormalModel> selDownGoodsPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 获取上架普通商品数量
     * @return
     */
    @Select("SELECT COUNT(g.goods_id) FROM goods g LEFT OUTER JOIN goods_stat gs ON g.goods_id = gs.goods_id " +
            "WHERE gs.is_upper = 1 AND g.is_ticket = 0" )
    Integer getNormalGoodsNum();

    /**
     * 查找上架普通商品分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<GoodsNormalModel> selNormalGoodsPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 获取上架卡券商品数量
     * @return
     */
    @Select("SELECT COUNT(g.goods_id) FROM goods g LEFT OUTER JOIN goods_stat gs ON g.goods_id = gs.goods_id " +
            "WHERE gs.is_upper = 1 AND g.is_ticket = 1" )
    Integer getTicketGoodsNum();


    /**
     * 查找所有实体店卡券商品分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<GoodsTicketModel> selTicketGoodsPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 查找上架普通商品分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<PointGoods> selPointGoodsPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 按id查找普通商品信息
     * @param goodsId
     * @return
     */
    @Select("SELECT g.*, gs.*, s.* " +
            "FROM (goods g LEFT OUTER JOIN goods_stat gs ON g.goods_id = gs.goods_id ) " +
            "LEFT OUTER JOIN shop s ON g.shop_id = s.shop_id " +
            "WHERE g.goods_id = #{goodsId}")
    GoodsNormalModel selNormalGoodsById(@Param("goodsId")Integer goodsId);


    /**
     * 按id查找卡券商品信息
     * @param goodsId
     * @return
     */
    @Select("SELECT g.*, gs.*, s.*, t.* " +
            "FROM ((goods g LEFT OUTER JOIN goods_stat gs ON g.goods_id = gs.goods_id ) " +
            "LEFT OUTER JOIN shop s ON g.shop_id = s.shop_id)" +
            "LEFT OUTER JOIN ticket t ON t.goods_id = g.goods_id " +
            "WHERE g.goods_id = #{goodsId}")
    GoodsTicketModel selTicketGoodsById(@Param("goodsId")Integer goodsId);


    /**
     * 查找商家分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<Shop> selShopPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 查找用户分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<WxUser> selUserPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 计算订单总数
     * @param ordersStatus
     * @return
     */
    Integer countOrders(Integer ordersStatus);

    /**
     * 获取订单分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @param ordersStatus
     * @return
     */
    List<OrdersInfoModel> selOrdersPage(@Param("start")Integer start, @Param("num")Integer num,
                                        @Param("sort")Integer sort, @Param("order")Integer order, @Param("ordersStatus")Integer ordersStatus);


    /**
     * 获取列表商品总数量
     * @param ordersParam
     * @return
     */
    Integer countOrders2(@Param("ordersParam") OrdersParam ordersParam);

    /**
     * 查询商品列表分页
     * @param start
     * @param num
     * @param ordersParam
     * @return
     */
    List<OrdersInfoModel> selOrdersPage2(@Param("start")Integer start, @Param("num")Integer num, @Param("ordersParam")OrdersParam ordersParam);



    /**
     * 获取积分抽奖待发货订单分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<PointOrdersModel> selPointOrdersPage(@Param("start")Integer start, @Param("num")Integer num,
                               @Param("sort")Integer sort, @Param("order")Integer order);



    /**
     * 计算退款请求总数
     * @param refundStatus
     * @return
     */
    Integer countRefunds(Integer refundStatus);


    /**
     * 获取退款请求分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @param refundStatus
     * @return
     */
    List<RefundModel> selRefundsPage(@Param("start")Integer start, @Param("num")Integer num,
                                     @Param("sort")Integer sort, @Param("order")Integer order, @Param("refundStatus")Integer refundStatus);


    /**
     * 查找秒杀分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<SeckillModel> selSeckillPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);

    /**
     * 查找拍卖分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<AuctionModel> selAuctionPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 获取上架普通商品数量（可设置活动商品）/不包含卡券类商品
     * @return
     */
    @Select("SELECT COUNT(g.goods_id) FROM goods g LEFT OUTER JOIN goods_stat gs ON g.goods_id = gs.goods_id " +
            "WHERE gs.is_upper <> 2 AND g.is_ticket=0" )
    Integer getGoodsForActivityNum();

    /**
     * 查找上架商品分页（可设置活动商品）
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<GoodsNormalModel> selGoodsForActivityPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 获取最新一期秒杀
     * @return
     */
    @Select("SELECT s.*, g.goods_pic, g.goods_name FROM seckill s LEFT OUTER JOIN goods g ON s.goods_id=g.goods_id ORDER BY s.seckill_id DESC LIMIT 0,1")
    SeckillShowModel selSeckillShowModel();

    /**
     * 获取最新一期拍卖
     * @return
     */
    @Select("SELECT a.*, g.goods_pic, g.goods_name, "
            + "IF(IFNULL(a.wx_user_id,'')='',0,1) AS is_finished "
            + "FROM auction a LEFT OUTER JOIN goods g ON a.goods_id=g.goods_id ORDER BY a.auction_id DESC LIMIT 0,1")
    AuctionShowModel selAuctionShowModel();

    /**
     * 查找今日特价列表
     * @return
     */
    @Select("SELECT o.onsale_id, o.goods_id, o.onsale_price, "
            + "g.goods_name, g.goods_pic, g.goods_price "
            + "FROM onsale o LEFT OUTER JOIN goods g ON o.goods_id = g.goods_id")
    List<OnsaleShowModel> selOnsaleShowModel();


    /**
     * 查找待审核视频动态
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<Moment> selUncheckedMomentPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);

    /**
     * 查找已通过视频动态
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<MomentModel> selMomentPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 查找提现请求分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<CashoutModel> selCashoutPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 查找广告请求分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<Billboard> selBillboardPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);



    /**
     * 获取优惠券模板数量
     * @return
     */
    @Select("SELECT COUNT(tem_id) FROM tem WHERE tem.is_delete = 0" )
    Integer getTemTotalNum();

    /**
     * 查找优惠券模板分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<Tem> selTemPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 查找优惠券分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<CouponShowModel> selCouponPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);

    /**
     * 批量插入优惠券
     * @param list
     * @return
     */
    Integer insertBatchCoupon(List<Coupon> list);


    /**
     * 查找加盟请求分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<Contact> selContactPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 查找设计师分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<Designer> selDesignerPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 查找预约分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<AppointModel> selAppointPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 查找上门量房预约分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<AppointMeasureModel> selAppointMeasurePage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 查找订单详情
     * @param ordersId
     * @return
     */
    OrdersDetailModel selOrdersDetailById(Integer ordersId);


    /**
     * 求和一整天的销售额
     * @param yesterday
     * @param today
     * @return
     */
    @Select("SELECT SUM(orders_price) FROM orders WHERE orders_status IN (1,2,3,9) AND pay_time BETWEEN #{yesterday} AND #{today}")
    BigDecimal selSalesSum(@Param("yesterday") Date yesterday, @Param("today") Date today);


    /**
     * 查询动态评论分页 排序：时间
     * @param start
     * @param num
     * @param momentId
     * @return
     */
    @Select("SELECT m.moment_com_id, m.moment_com_text, m.moment_com_time, "
            + "w.wx_user_id, w.nickname, w.headimgurl "
            + "FROM moment_com m LEFT OUTER JOIN wx_user w "
            + "ON m.wx_user_id = w.wx_user_id "
            + "WHERE m.moment_id = #{momentId} "
            + "ORDER BY m.moment_com_time DESC LIMIT #{start},#{num}")
    List<MomentComShowModel> selMomentComShowPage(@Param("start")Integer start, @Param("num")Integer num, @Param("momentId")Integer momentId);


    /**
     * 查询未使用的个人优惠券信息
     * @param wxUserId
     * @return
     */
    @Select("SELECT c.coupon_id, c.coupon_time, c.end_time, c.is_used, t.tem_id, t.tem_name, t.tem_type, t.tem_number, t.tem_range, t.tem_bottom_price, t.tem_timespan "
            + "FROM coupon c, tem t "
            + "WHERE c.tem_id=t.tem_id AND c.wx_user_id=#{wxUserId} AND c.is_used=0 "
            + "ORDER BY c.end_time ASC")
    List<CouponInfoModel> getUnusedCouponInfo(Integer wxUserId);


    /**
     * 查找拍卖分页
     * @param start
     * @param num
     * @param sort
     * @param order
     * @return
     */
    List<Admin> selAdminPage(@Param("start")Integer start, @Param("num")Integer num, @Param("sort")Integer sort, @Param("order")Integer order);


    /**
     * 返回客服聊天内容
     * @param start
     * @param num
     * @param wxUserId
     * @return
     */
    @Select("SELECT c.*, w.nickname, w.headimgurl "
            + "FROM chat c LEFT OUTER JOIN wx_user w ON c.wx_user_id = w.wx_user_id "
            + "WHERE c.wx_user_id = #{wxUserId} "
            + "ORDER BY chat_id ASC LIMIT #{start},#{num}")
    List<ChatShowModel> selChatList(@Param("start")Integer start, @Param("num")Integer num, @Param("wxUserId")Integer wxUserId);


    /**
     * 客服：未回复的聊天窗口数量
     * @return
     */
    Integer countUnreadChat();

    /**
     * 客服：全部聊天窗口数量
     * @return
     */
    Integer countAllChat();


    /**
     * 获取未读列表
     * @return
     */
    List<ChatGeneralModel> getUnreadList(@Param("start")Integer start, @Param("num")Integer num);

    /**
     * 获取全部列表
     * @return
     */
    List<ChatGeneralModel> getAllList(@Param("start")Integer start, @Param("num")Integer num);


    /**
     * 获取商品销量
     * @param goodsId
     * @param begin
     * @param end
     * @return
     */
    BigDecimal getGoodsSales(@Param("goodsId")Integer goodsId, @Param("begin")Date begin, @Param("end")Date end);


    /**
     * 获取商品销量
     * @param shopId
     * @param begin
     * @param end
     * @return
     */
    BigDecimal getShopSales(@Param("shopId")Integer shopId, @Param("begin")Date begin, @Param("end")Date end);

}
